package logic

import (
	"context"
	"rpc/pb/rpc"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type InsertLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInsertLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InsertLogic {
	return &InsertLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InsertLogic) Insert(req *types.Request) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, err := l.svcCtx.Rpc.GetMeesage(context.Background(), &rpc.Request{Goodsname: req.Name})
	if err != nil {
		return &types.Response{
			Data: err.Error(),
		}, nil
	}
	return &types.Response{
		Toltal:      res.Toltal,
		Perpage:     res.Perpage,
		Currentpage: res.Currentpage,
		Lastpage:    res.Lastpage,
		Data:        res.Data,
	}, nil
}
